import { Component } from "react"
import store from '../store/index' 





const connect = (m2p)=>{
    const hoc = (Cp1)=>{
        class newCp   extends Component{
            state = {
                storestate:null
            }
            componentDidMount(){
                this.setState({
                    storestate: store.getState()
                })
                store.subscribe(()=>{
                    const curstate = store.getState() 
                    this.setState({
                        storestate: curstate
                    })
                })
            }
            render(){
                return <Cp1 
                        {...m2p(this.state.storestate)}  
                         disapatch={store.dispatch}
                         />
            }
        }
        return newCp;
    }

    return hoc
        
}
